unit CheckEditFrm;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, cxGraphics, cxControls, cxLookAndFeels,
  cxLookAndFeelPainters,  cxContainer, cxEdit, dxLayoutcxEditAdapters,
  dxLayoutContainer, cxTextEdit, cxMaskEdit, cxSpinEdit, dxLayoutControl,
  dxLayoutControlAdapters, Vcl.Menus, Vcl.StdCtrls, cxButtons, Vcl.ButtonGroup,
  Vcl.Touch.Keyboard, Vcl.Touch.KeyboardTypes, dxLayoutLookAndFeels, cxClasses,
  dxSkinsCore, dxSkinOffice2010Blue, dxSkinOffice2013White, dxSkinscxPCPainter,
  System.Bindings.Helper,
  CashCheckUnit, dxSkinOffice2010Black;

type
  TCheckEditForm = class(TForm)
    lg1: TdxLayoutGroup;
    lc1: TdxLayoutControl;
    lglc1Group1: TdxLayoutGroup;
    lglc1Group3: TdxLayoutGroup;
    SpinEdit_Zakaz: TcxSpinEdit;
    itm_lc1Item11: TdxLayoutItem;
    SpinEdit_Guest: TcxSpinEdit;
    itm_lc1Item12: TdxLayoutItem;
    SpinEdit_table: TcxSpinEdit;
    itm_lc1Item1: TdxLayoutItem;
    tchkybrd1: TTouchKeyboard;
    itm_lc1Item14: TdxLayoutItem;
    lglc1Group2: TdxLayoutGroup;
    btn_Ok: TcxButton;
    itm_lc1Item13: TdxLayoutItem;
    btn_Cancel: TcxButton;
    itm_lc1Item15: TdxLayoutItem;
    dxlytlkndflst1: TdxLayoutLookAndFeelList;
    dxlytcxlkndfl1: TdxLayoutCxLookAndFeel;
    procedure FormCreate(Sender: TObject);
    procedure btn_CancelClick(Sender: TObject);
    procedure btn_OkClick(Sender: TObject);

    procedure SpinEdit_tableEnter(Sender: TObject);
    procedure SpinEdit_ZakazPropertiesChange(Sender: TObject);
    procedure SpinEdit_ZakazPropertiesValidate(Sender: TObject;
      var DisplayValue: Variant; var ErrorText: TCaption; var Error: Boolean);
    procedure SpinEdit_tablePropertiesChange(Sender: TObject);
    procedure SpinEdit_GuestPropertiesChange(Sender: TObject);
    procedure SpinEdit_tablePropertiesEditValueChanged(Sender: TObject);
    procedure SpinEdit_GuestPropertiesValidate(Sender: TObject;
      var DisplayValue: Variant; var ErrorText: TCaption; var Error: Boolean);
    procedure SpinEdit_tablePropertiesValidate(Sender: TObject;
      var DisplayValue: Variant; var ErrorText: TCaption; var Error: Boolean);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
    procedure InitLinks;
    function Validate: Boolean;
  public
    { Public declarations }
    CashCheck: TCashCheck;
    //constructor Create(AOwner: TComponent; chek: TCashCheck);
  end;

var
  CheckEditForm: TCheckEditForm;

implementation

{$R *.dfm}

procedure TCheckEditForm.btn_CancelClick(Sender: TObject);
begin
  ModalResult:= mrCancel;
end;

procedure TCheckEditForm.btn_OkClick(Sender: TObject);
begin
  if Validate then
    ModalResult:= mrOk;
end;

procedure TCheckEditForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  CashCheck.Free;
end;

procedure TCheckEditForm.FormCreate(Sender: TObject);
begin
  tchkybrd1.Layout:='NumPad1';
  CashCheck:= TCashCheck.Create;
  //InitLinks;
end;

procedure TCheckEditForm.InitLinks;
begin
  //CashCheck.Bind('NumTable', SpinEdit_table, 'EditValue');
  //CashCheck.Bind('NumZakaz', SpinEdit_Zakaz, 'EditValue');
  //CashCheck.Bind('NumGuest', SpinEdit_Guest, 'EditValue');
end;

procedure TCheckEditForm.SpinEdit_tableEnter(Sender: TObject);
var
  AEdit: TcxCustomEdit;
begin
  AEdit:= (Sender as TcxSpinEdit);
  if AEdit.EditValue = 0 then
    if AEdit.InnerControl.HandleAllocated then
     PostMessage(AEdit.InnerControl.Handle, EM_SETSEL, 0, -1);
end;

procedure TCheckEditForm.SpinEdit_GuestPropertiesChange(Sender: TObject);
begin
  TBindings.Notify(Sender, 'EditValue');
end;

procedure TCheckEditForm.SpinEdit_GuestPropertiesValidate(Sender: TObject;
  var DisplayValue: Variant; var ErrorText: TCaption; var Error: Boolean);
begin
  Error:= DisplayValue<1;
end;

procedure TCheckEditForm.SpinEdit_tablePropertiesChange(Sender: TObject);
begin
  TBindings.Notify(Sender, 'EditValue');
end;

procedure TCheckEditForm.SpinEdit_tablePropertiesEditValueChanged(
  Sender: TObject);
begin
  TBindings.Notify(Sender, 'EditValue');
end;

procedure TCheckEditForm.SpinEdit_tablePropertiesValidate(Sender: TObject;
  var DisplayValue: Variant; var ErrorText: TCaption; var Error: Boolean);
begin
  Error:= DisplayValue<1;
end;

procedure TCheckEditForm.SpinEdit_ZakazPropertiesChange(Sender: TObject);
begin
  TBindings.Notify(Sender, 'EditValue');
end;

procedure TCheckEditForm.SpinEdit_ZakazPropertiesValidate(Sender: TObject;
  var DisplayValue: Variant; var ErrorText: TCaption; var Error: Boolean);
begin
  Error:= DisplayValue<1;
end;

function TCheckEditForm.Validate: Boolean;
begin
  Result:= False;
  if not SpinEdit_table.ValidateEdit(true) then Exit;
  Result:= True;
end;

end.
